import 'package:flutter/material.dart';

class ListViewSeparatedDemo extends StatelessWidget {
  const ListViewSeparatedDemo({super.key});

  @override
  Widget build(BuildContext context) {
    /// 下划线widget预定义以供复用
    Widget divider1 = const Divider(color: Colors.blue);
    Widget divider2 = const Divider(color: Colors.red);
    return Scaffold(
      appBar: AppBar(
        title: const Text('ListViewSeparatedDemo'),
      ),
      body: ListView.separated(
        itemCount: 100,

        /// 列表项构造器
        itemBuilder: (BuildContext context, int index) {
          return ListTile(
            title: Text("$index"),
          );
        },

        /// 分割器构造器
        separatorBuilder: (BuildContext context, int index) {
          return index % 2 == 0 ? divider1 : divider2;
        },
      ),
    );
  }
}
